﻿using System;
using AccessControl.Contracts.Models;
using AccessControl.Contracts.Settings;
using AccessControl.Data.Models;

namespace AccessControl.Wpf.Settings.ViewModels
{
	class CamerasSettingsViewModel : SettingsBaseViewModel<ICamera>
	{
		#region Public Constructor

		public CamerasSettingsViewModel(ISettingsService settingsService) 
			: base(settingsService.Cameras)
		{
			Name = "Cameras";
		}

		#endregion

		#region SettingsBaseViewModel Overrides

		public override void AddItem(ICamera item)
		{
			SettingsService.Add(item);
		}

		public override void EditItem(ICamera item)
		{
			SettingsService.Update(item);
		}

		public override void DeleteItem(ICamera item)
		{
			SettingsService.Delete(item);
		}

		public override bool IsValidItem(ICamera item)
		{
			if (item.Ip == null)
			{
				MessagingService.Show("IP is not valid", "AccessControl", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
				return false;
			}

			if (item.PortNumber <= 0)
			{
				MessagingService.Show("Port number is not valid", "AccessControl", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
				return false;
			}

			if (item.RelatedEntryId == 0)
			{
				MessagingService.Show("No related entry is selected", "AccessControl", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation);
				return false;
			}

			return true;
		}

		public override ICamera CreateNewItem()
		{
			return new Camera();
		}

		#endregion
	}
}
